# -*- coding: utf-8 -*-
# @File     : serializers.py
# @Author   : bingjia
# @Time     : 2020/8/11 10:32
# @Desc     :

from operation.base.api import serializers

from . import models


class DataSerializer(serializers.ModelSerializer):
    """
    数据序列化
    """
    project = serializers.SerializerMethodField()

    class Meta:
        model = models.SrcData
        fields = ['id', 'name', 'data_size', 'project',
                  'thermal_image', 'visible_image', 'created_date']

    def get_project(self, obj):
        return obj.project.name


class SrcDataAdminSerializer(serializers.ModelSerializer):
    """
    数据序列化
    """
    project = serializers.SerializerMethodField()

    class Meta:
        model = models.SrcData
        fields = ['id', 'name', 'data_size', 'project',
                  'thermal_image', 'visible_image', 'created_date']

    def get_project(self, obj):
        return obj.project.name


class MarkDataAdminSerializer(serializers.ModelSerializer):
    """
    数据序列化
    """
    data_type = serializers.SerializerMethodField()

    class Meta:
        model = models.SrcData
        fields = ['id', 'name', 'category', 'mark_date', 'data_type']

    def get_data_type(self, obj):
        return obj.data_type.split(",")
